//
//  SearchPlayerLayer.cpp
//  airfight
//
//  Created by lahm on 12-12-7.
//  Copyright (c) 2012年 moonriver. All rights reserved.
//

#include "SearchPlayerLayer.h"
#include "MenuLayer.h"
#include "BattleLoadingLayer.h"

bool SearchPlayerLayer::init()
{
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    m_SpriteFrameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
    m_SpriteFrameCache->addSpriteFramesWithFile("airfight.plist","airfight.png");
    m_SpriteBatch = CCSpriteBatchNode::create("airfight.png");
    
    CCSprite *back = CCSprite::create();
    back->initWithSpriteFrameName("base.png");
    back->setPosition(ccp(160, 240));
    addChild(back);
    
    CCMenuItemFont::setFontSize(15);
    
    CCLabelTTF *labelTitle = CCLabelTTF::labelWithString("寻找对手", CCSize(150, 50), kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter, "", 30);
    labelTitle->setPosition(ccp(160,380));
    addChild(labelTitle);
    
    CCLabelTTF *lable1 = CCLabelTTF::labelWithString("AAA 15", CCSize(100, 50), kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter, "", 15);
    lable1->setPosition(ccp(90, 280));
    addChild(lable1);
    
    CCLabelTTF *lable2 = CCLabelTTF::labelWithString("ABC 20", CCSize(100, 50), kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter, "", 15);
    lable2->setPosition(ccp(90, 240));
    addChild(lable2);
    
    CCLabelTTF *lable3 = CCLabelTTF::labelWithString("KKK 12", CCSize(100, 50), kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter, "", 15);
    lable3->setPosition(ccp(90, 200));
    addChild(lable3);
    
    CCLabelTTF *lable4 = CCLabelTTF::labelWithString("SSD 15", CCSize(100, 50), kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter, "", 15);
    lable4->setPosition(ccp(90, 160));
    addChild(lable4);
    
    CCSprite *start1Btn = CCSprite::create();
    start1Btn->initWithSpriteFrameName("button.png");
    CCSprite *start1BtnClicked = CCSprite::create();
    start1BtnClicked->initWithSpriteFrameName("button.png");
    start1BtnClicked->setScale(0.95);
    CCMenuItemSprite *start1MenuItem = CCMenuItemSprite::itemWithNormalSprite(start1Btn, start1BtnClicked, start1Btn, this, menu_selector(SearchPlayerLayer::clickStart));
    start1MenuItem->setPosition(ccp(220, 280));
    CCLabelTTF *labelStart1 = CCLabelTTF::labelWithString("开战", CCSize(50, 30), kCCTextAlignmentLeft, kCCVerticalTextAlignmentCenter, "", 15);
    labelStart1->setPosition(ccp(230, 282));
    
    CCSprite *start2Btn = CCSprite::create();
    start2Btn->initWithSpriteFrameName("button.png");
    CCSprite *start2BtnClicked = CCSprite::create();
    start2BtnClicked->initWithSpriteFrameName("button.png");
    start2BtnClicked->setScale(0.95);
    CCMenuItemSprite *start2MenuItem = CCMenuItemSprite::itemWithNormalSprite(start2Btn, start2BtnClicked, start2Btn, this, menu_selector(SearchPlayerLayer::clickStart));
    start2MenuItem->setPosition(ccp(220, 240));
    CCLabelTTF *labelStart2 = CCLabelTTF::labelWithString("开战", CCSize(50, 30), kCCTextAlignmentLeft, kCCVerticalTextAlignmentCenter, "", 15);
    labelStart2->setPosition(ccp(230, 242));
    
    CCSprite *start3Btn = CCSprite::create();
    start3Btn->initWithSpriteFrameName("button.png");
    CCSprite *start3BtnClicked = CCSprite::create();
    start3BtnClicked->initWithSpriteFrameName("button.png");
    start3BtnClicked->setScale(0.95);
    CCMenuItemSprite *start3MenuItem = CCMenuItemSprite::itemWithNormalSprite(start3Btn, start3BtnClicked, start3Btn, this, menu_selector(SearchPlayerLayer::clickStart));
    start3MenuItem->setPosition(ccp(220, 200));
    CCLabelTTF *labelStart3 = CCLabelTTF::labelWithString("开战", CCSize(50, 30), kCCTextAlignmentLeft, kCCVerticalTextAlignmentCenter, "", 15);
    labelStart3->setPosition(ccp(230, 202));
    
    CCSprite *start4Btn = CCSprite::create();
    start4Btn->initWithSpriteFrameName("button.png");
    CCSprite *start4BtnClicked = CCSprite::create();
    start4BtnClicked->initWithSpriteFrameName("button.png");
    start4BtnClicked->setScale(0.95);
    CCMenuItemSprite *start4MenuItem = CCMenuItemSprite::itemWithNormalSprite(start4Btn, start4BtnClicked, start4Btn, this, menu_selector(SearchPlayerLayer::clickStart));
    start4MenuItem->setPosition(ccp(220, 160));
    CCLabelTTF *labelStart4 = CCLabelTTF::labelWithString("开战", CCSize(50, 30), kCCTextAlignmentLeft, kCCVerticalTextAlignmentCenter, "", 15);
    labelStart4->setPosition(ccp(230, 162));
    
    CCSprite *backBtn = CCSprite::create();
    backBtn->initWithSpriteFrameName("button.png");
    CCSprite *backBtnClicked = CCSprite::create();
    backBtnClicked->initWithSpriteFrameName("button.png");
    backBtnClicked->setScale(0.95);
    CCMenuItemSprite *backMenuItem = CCMenuItemSprite::itemWithNormalSprite(backBtn, backBtnClicked, backBtn, this, menu_selector(SearchPlayerLayer::clickBack));
    backMenuItem->setPosition(ccp(220, 100));
    CCLabelTTF *labelBack = CCLabelTTF::labelWithString("返回", CCSize(50, 30), kCCTextAlignmentLeft, kCCVerticalTextAlignmentCenter, "", 15);
    labelBack->setPosition(ccp(230, 102));
    
    CCMenu *menu = CCMenu::menuWithItems(start1MenuItem, start2MenuItem, start3MenuItem, start4MenuItem, backMenuItem, NULL);
    menu->setPosition(CCPointZero);
    addChild(menu);
    addChild(labelStart1);
    addChild(labelStart2);
    addChild(labelStart3);
    addChild(labelStart4);
    addChild(labelBack);
    
    return true;
}

void SearchPlayerLayer::startLoading()
{
    
}

void SearchPlayerLayer::onEnter()
{
    CCLayer::onEnter();
    scheduleOnce(schedule_selector(SearchPlayerLayer::startLoading), 0);
}

void SearchPlayerLayer::clickBack()
{
    CCScene *pScene = CCScene::create();
    CCLayer *pLayer = MenuLayer::create();
    pScene->addChild(pLayer);
    CCDirector::sharedDirector()->replaceScene(pScene);
}

void SearchPlayerLayer::clickStart()
{
    CCScene *pScene = CCScene::create();
    CCLayer* loadingLayer = BattleLoadingLayer::create();
    CCLayerMultiplex* layer = CCLayerMultiplex::createWithLayer(loadingLayer);
    layer->m_bIsRunning = true;
    pScene->addChild(layer, 0);
    CCDirector::sharedDirector()->replaceScene(pScene);
}
